require "wondercap/lib/utils/time_converter"
require "time"

extension :revision => :generic do
  task :fill_real_revision do
    execute_previous
    next logger.debug("no scm defined - bypassing revision generalizing") if scm.nil?

    logger.debug "querying revision '#{real_revision}' from #{scm}"
    real_rev = scm.query_revision(real_revision) do |cmd|
      syscmd_output cmd
    end
    if !real_rev
      real_rev = TimeConverter.time_to_int((real_revision == scm.head) ? Time.now : Time.parse(real_revision))
    else
      real_rev = Integer(real_rev)
    end

    logger.info "real revision: #{real_rev}"
    set :real_revision, real_rev
  end
end
